import ArrayUtil from '@/ArrayUtil';
import PlayerUtil from '@/PlayerUtil';
import RandomUtil from '@/RandomUtil';
import UnitItemEvent from '@/event/UnitItemEvent';
import { d_shop_items } from 'xlsx/shop_items';

export default class Item_新手礼包 {
    constructor() {
        se.onUnitUseItem(this.action);
    }
    action(this: void, d: UnitItemEvent) {
        let it = d.manipulatedItem;
        let type = id2string(GetItemTypeId(it));
        if (type != 'GI00') return;
        let u = d.trigUnit;
        let 技能列表 = GlobalDB.ItemDB.normalSkillBooks.map((item) => item.id);

        for (let i = 0; i < 2; i++) {
            let skid = ArrayUtil.randomElement(技能列表);
            UnitAddItemById(u, skid);
        }
        let 物品列表 = d_shop_items.filter((item) => item.goldcost <= 2500 && !item.Name.includes('卷轴')).map((item) => item.id);
        // 添加装备
        for (let i = 0; i < 2; i++) {
            let id = ArrayUtil.randomElement(物品列表);
            UnitAddItemById(u, id);
        }
        // 添加金币
        let g = RandomUtil.nextInt(0, 2000);
        PlayerUtil.addGoldState(GetOwningPlayer(u), g);
    }
}
